package cn.javass.dp.builder.example3;

import java.util.Collection;
import java.util.Map;

public class XmlBuilder implements Builder {

    private StringBuffer buffer = new StringBuffer();

    @Override
    public void buildHeader(ExportHeaderModel ehm) {
        buffer.append("<?xml version='1.0' encoding='gb2132' ?>\n");
        buffer.append("<depId>"+ehm.getDepId()+"</depId>+\n");
        buffer.append("<Exportdate>"+ehm.getDepId()+"</Exportdate>+\n");
    }

    @Override
    public void buildBody(Map<String, Collection<ExportDataModel>> mapData) {
        for (String tblName : mapData.keySet()) {
            buffer.append("<>"+tblName+"</>\n");

            for (ExportDataModel edm : mapData.get(tblName)) {
                buffer.append("<>"+edm.getProductId()+"</>\n");
                buffer.append("<>"+edm.getPrice()+"</>\n");
                buffer.append("<>"+edm.getAmount()+"</>\n");
            }
        }
    }

    @Override
    public void buildFooter(ExportFooterModel efm) {
        buffer.append("<>"+efm.getExportUser()+"</>+\n");
    }

    @Override
    public StringBuffer getResult() {
        return buffer;
    }
}
